package com.jic.product.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.product.entity.BrandManagement;
import com.jic.product.manage.request.BrandManagementRequest;
import com.jic.product.manage.response.BrandManagementResponse;
import com.jic.product.manage.response.ProductBrandResponse;
import com.jic.product.mapper.BrandManagementMapper;
import com.jic.product.service.BrandManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品品牌资质管理
 * @author :
 * @email :
 * @since : 2020-01-10 07:03:01
 * @version : v1.0.0
 */
@Service
public class BrandManagementServiceImpl implements BrandManagementService{

    @Autowired
    private BrandManagementMapper brandManagementMapper;

    @Override
    public long insert(BrandManagementRequest brandManagement) {
        long flag = brandManagementMapper.insert(brandManagement);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return brandManagementMapper.delete(id);
    }

    @Override
    public long update(BrandManagementRequest brandManagement) {
        return brandManagementMapper.update(brandManagement);
    }

    @Override
    public BrandManagement queryByPrimaryKey(Long id){
        return brandManagementMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<BrandManagement> query(BrandManagement brandManagement){
        return brandManagementMapper.query(brandManagement);
    }

    @Override
    public PageResult<BrandManagementResponse> queryPage(BrandManagementRequest brandManagement, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<BrandManagementResponse> list = brandManagementMapper.queryPage(startIndex, pageQuery.getLimit(), brandManagement);
        long count = brandManagementMapper.queryPageCount(brandManagement);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public RestResult queryInfo(BrandManagementRequest t) {
        RestResult restResult=new RestResult();
        BrandManagementResponse list = brandManagementMapper.queryInfo(t);
        restResult.setData(list);
        return restResult;
    }

    @Override
    public List<ProductBrandResponse> queryMerchantProductBrand(BrandManagementRequest brandManagement) {
        return  brandManagementMapper.queryMerchantProductBrand(brandManagement);
    }
}
